#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
typedef pair<int,int> pii;
int q;
int n;
vector<pii> t;
pii calc(pii a, pii b){
  if(a.first > b.first)swap(a,b);
  int k = max(min(b.second - b.first + 1,a.second - b.first + 1),0);
  int r = max(a.second,b.second) - min(a.first,b.first);
  return {k,r};
}
int res = INT_MAX, ans = 0;
namespace BF{
  void work(){
    while(q--){
      char op;
      int l,r;
      cin >> op >> l >> r;
      --r;
      if(op == 'A'){
        if(n == 0){
          res = r - l + 1, ans = r - l;
        }else{
          for(int i = 0; i < t.size(); ++ i){
            pii rt = calc({l,r},t[i]);
            // cerr << l << ',' << r << "+" << t[i].first << ',' << t[i].second << ":" << rt.first << " " << rt.second << "\n";
            if(rt.first == res){
              ans = min(ans,rt.second);
            }else if(rt.first < res){
              res = rt.first;
              ans = rt.second;
            }
          }
        }
        ++n;
        t.push_back({l,r});
      }else{
        t.erase(find(t.begin(),t.end(),make_pair(l,r)));
        // for(int i = 0; i < t.size(); ++ i){
          // cout << t[i].first << t[i].second << "\n";
        // }
        --n;
        res = INT_MAX,ans = 0;
        if(n == 1){
          res = t[0].second - t[0].first + 1;
          ans = t[0].second - t[0].first;
        }else{
          for(int i = 0; i < t.size(); ++ i){
            for(int j = i + 1; j < t.size(); ++ j){
              pii rt = calc(t[i],t[j]);
              // cout << t[i].first << " " << t[i].second << " + " << t[j].first << t[j].second << ":" << rt.first << "," << rt.second << "\n";
              if(rt.first == res){
                ans = min(ans,rt.second);
              }else if(rt.first < res){
                res = rt.first;
                ans = rt.second;
              }
            }
          }
        }
      }
      cout << ans+1 << "\n";

    }
  }
}
int main(){
  freopen("stone.in","r",stdin);
  freopen("stone.out","w",stdout);
  cin >> q;
  if(q <= 500){
    BF::work();
  }else{
    while(q--){
      char op;
      int l,r;
      cin >> op >> l >> r;
      --r;
      if(op == 'A'){
        if(n == 0){
          res = r - l + 1, ans = r - l;
        }else{
          for(int i = 0; i < t.size(); ++ i){
            pii rt = calc({l,r},t[i]);
            // cerr << l << ',' << r << "+" << t[i].first << ',' << t[i].second << ":" << rt.first << " " << rt.second << "\n";
            if(rt.first == res){
              ans = min(ans,rt.second);
            }else if(rt.first < res){
              res = rt.first;
              ans = rt.second;
            }
          }
        }
        ++n;
        t.push_back({l,r});
      }else{
        t.erase(find(t.begin(),t.end(),make_pair(l,r)));
        --n;
        if(n == 1){
          res = t[0].second - t[0].first + 1;
          ans = t[0].second - t[0].first;
        }else{
          if(t.size() <= 50){
            res = INT_MAX,ans = 0;
            for(int i = 0; i < t.size(); ++ i){
              for(int j = i + 1; j < t.size(); ++ j){
                pii rt = calc(t[i],t[j]);
                if(rt.first == res){
                  ans = min(ans,rt.second);
                }else if(rt.first < res){
                  res = rt.first;
                  ans = rt.second;
                }
              }
            }
          }
        }
      }
      cout << ans+1 << "\n";
    }
  }
  return 0;
}